﻿@model Wicresoft.EKA.ITSM.Business.SMGXJPlanTicketModel

@{
    ViewBag.Title = "巡检模板" + ViewBag.TicketID;
    Layout = "~/Views/Shared/_LayoutKoJS.cshtml";
    var officeCount = ViewBag.Groups.Count;
}


    <div class="aux-body">
        <!--<h1 class="itemtitle">My Resource</h1> -->
        <div class="aux-tabcontent">
            <div class="fx-grid">
                <div id="fx-scrollbar" style="width: 900px;">
                    <!-- style变化 height:650px; -->
                    <div id="fx-scrollbar-scrollable" style="width: 950px;">
                        <!-- style变化 -->
                        <div class="fx-grid-container fx-scrollbar-content" style="overflow: visible; width: 900px;">
                            <!-- style变化 -->
                            <div class="quickStarttab" style="height: 140px">
                                <form id="KSForm">
                                    <div id="Ticketfield">
                                        <div class="quickStarttab-item">
                                            <label>模板名称：</label>
                                            <input type="text" name="cChr_Name" id="cChr_Name" class="required">
                                        </div>
                                        <div class="quickStarttab-item">
                                            <label>模板ID：</label>
                                            <input type="text" name="cChr_TicketID" id="cChr_TicketID" value="@ViewBag.TicketID" readonly="true" class="required" style="background-color:#ECECEC;">
                                        </div>

                                        <div class="quickStarttab-item" style="width: 100%;">
                                            <label>模板描述：</label>
                                            <input type="text" name="cChr_Description" id="cChr_Description" class="input_all">
                                        </div>
                                        @{if (officeCount == 1)
                                          { 
                                            <div class="quickStarttab-item">
                                                <label>部门：</label>
                                                <select name="cChr_Office" id="cChr_Office" class="required" style="width: 272px">
                                                    <option value="@ViewBag.Groups[0].GroupID" selected>@ViewBag.Groups[0].GroupName</option>
                                                </select>
                                                @*<input type="text" name="cChr_Office" id="cChr_Office" value="@ViewBag.Groups[0].GroupName" readonly="true" class="required" style="background-color:#ECECEC;">*@
                                            </div>
                                          }
                                          else if (officeCount > 1)
                                          {
                                              <div class="quickStarttab-item">
                                                <label>部门：</label>
                                                <select name="cChr_Office" id="cChr_Office" class="required" style ="width:272px">
                                                    @foreach(var item in ViewBag.Groups){
                                                        <option value="@item.GroupID">@item.GroupName</option>
                                                    }
                                                    </select>
                                            </div>
                                          }
                                        }
                                    <div class="quickStarttab-item">
                                        <label>是否公开：</label>
                                            <input type="radio" name="cChr_Department" value="public"  >公有
                                            <input type="radio" name="cChr_Department" value="private"  checked>私有
                                    </div>
                                        <div class="quickStarttab-item">
                                            <label>创建时间：</label>
                                            <input type="text" name="CreateDate" id="CreateDate" value="@ViewBag.CreateTime" readonly="true" class="required" style="background-color:#ECECEC;">
                                        </div>
                                        <div class="quickStarttab-item">
                                            <label>创建人：</label>
                                            <input type="text" name="cChr_FullName" id="cChr_FullName" value="@ViewBag.fullname" readonly="true" class="required" style="background-color:#ECECEC;">
                                        </div>
                                        <div style="float: right; display:none;  margin-right: 42px; margin-top: 3px">
                                            <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="FormSaveCreate" type="submit"><span class="ui-button-text">Save</span></button>
                                        </div>
@*                                        <div class="quickStarttab-item" style="width: 100%;">
                                            <div style="float: right; display: inline-block; margin-right: 42px;">
                                                <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="FormSave" type="submit"><span class="ui-button-text">Save</span></button>
                                            </div>
                                        </div>*@
                                    </div>
                                </form>
                            </div>
                            <div class="clear"></div>
                            <div id="menuCI" style="margin: 5px 0;">
                                <ul>
                                    <li id="m1" class="on"><a onclick="javascript:gopage(1)">服务器</a></li>
                                    <li id="m2"><a onclick="javascript:gopage(2)">交换机</a></li>
                                    <li id="m3"><a onclick="javascript:gopage(3)">存储</a></li>
                                    <li id="m4"><a onclick="javascript:gopage(4)">机房保障</a></li>
                                    <li id="m5"><a onclick="javascript:gopage(5)">数据库</a></li>
                                    <li id="m6"><a onclick="javascript:gopage(6)">安全设备</a></li>
                                    <li id="m7"><a onclick="javascript:gopage(7)">其他</a></li>
                                </ul>
                            </div>
                            <div id="wrap" style="margin: 5px 0;">
                                <div id="contentCI">
                                    <div id="c1">
                                        <h1>服务器</h1>
                                        @{Html.RenderPartial("../CI/Server");}
                                    </div>
                                    <div id="c2" style="display: none">
                                        <h1>交换机</h1>
                                         @{Html.RenderPartial("../CI/Switch");}
                                    </div>
                                    <div id="c3" style="display: none">
                                        <h1>存储</h1>
                                           @{Html.RenderPartial("../CI/Storage");}
                                    </div>
                                    <div id="c4" style="display: none">
                                        <h1>机房保障</h1>
                                         @{Html.RenderPartial("../CI/EngineRoom");}
                                    </div>
                                    <div id="c5" style="display: none">
                                        <h1>数据库</h1>
                                          @{Html.RenderPartial("../CI/DataBase");}
                                    </div>
                                    <div id="c6" style="display: none">
                                        <h1>安全设备</h1>
                                           @{Html.RenderPartial("../CI/SafetyEquipment");}
                                    </div>
                                     <div id="c7" style="display: none">
                                        <h1>其它</h1>
                                           @{Html.RenderPartial("../CI/Other");}
                                    </div>
                                </div>
                            </div>
                            <div style="display: inline-block; margin-left: 10px;">
                                <table id="gridTable1" style="width: 545px;"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- middle-over -->


<div id="DialogRD" style="height: 1000px"></div>

@section scripts {
    <script src="~/Scripts/zhaoyangdeerzi.js"></script>
    <script type="text/javascript">
        $("#LayoutCreate").addClass("selected");
        document.getElementById("SaveBtn").style.display = 'block';
        $("#SaveBtn").click(function () {
            $("#FormSaveCreate").click();
        });
        $(document).ready(function () {
            if('@officeCount' == 0){
                alert("您没有新建模板的权限，请联系管理员！");
                window.location.href = "/Home/InspectionConsole";
            }
            var GridrowID;
            var TableData = [];
            $('#KSForm').bind('submit', function () {
                if ($("#KSForm").valid()) {
                    TableData = [];
                    TableData = $("#gridTable1").jqGrid('getRowData');
                    $.ajax("/API/CIAPI?TicketID=" + '@ViewBag.TicketID', {
                        data: JSON.stringify(TableData),
                        type: "POST", contentType: "application/json",
                        async: false,
                        success: function (data) {
                        }
                    });

                    ajaxSubmit(this, function (data) {
                        alert(data);
                        $("#KSForm").removeClass('dirty');
                        window.location.href = "/InspectionTicket/Modify?TicketID=" + '@ViewBag.TicketID';
                    }, "/API/InspectionTicketAPI/");
                    return false;
                }
            });

            $("#KSForm").validate({
                errorLabelContainer: $("#signupForm div.error"),
                wrapper: "span",
                ignore: "",
            });

            $(".KSFormLittle").validate({
                errorLabelContainer: $("#signupForm div.error"),
                wrapper: "span",
                ignore: "",
            });

            //CI页面提交
            $('#KSFormServer').bind('submit', function () {
                event.preventDefault();
                if ($("#KSFormServer").valid()) {
                    //ajaxSubmit(this, function (data) {
                    //    alert(data);
                    //    $(':input:visible', '#KSFormServer').val('');
                    //    LoadHosts();
                    //}, "/API/CIAPI/");
                    if (!CheckName("#Server_CChr_DeviceName", "服务器")) return false;
                    AddToTable(this);
                }
                return false;
            });

            //交换机页面提交
            $('#KSFormSwitch').bind('submit', function () {
                event.preventDefault();
                if ($("#KSFormSwitch").valid()) {
                    //ajaxSubmit(this, function (data) {
                    //    alert(data);
                    //    $(':input:visible', '#KSFormSwitch').val('');
                    //    LoadHosts();
                    //}, "/API/CIAPI/");
                    if (!CheckName("#Switch_cChr_DeviceName", "交换机")) return false;
                    AddToTable(this);
                }
                return false;
            });

            //存储页面提交
            $('#KSFormStorage').bind('submit', function () {
                event.preventDefault();
                if ($("#KSFormStorage").valid()) {
                    //ajaxSubmit(this, function (data) {
                    //    alert(data);
                    //    $(':input:visible', '#KSFormStorage').val('');
                    //    LoadHosts();
                    //}, "/API/CIAPI/");
                    if (!CheckName("#Storage_CChr_Location", "存储")) return false;
                    AddToTable(this);
                }
                return false;
            });

            //机房保障页面提交
            $('#KSFormEngineRoom').bind('submit', function () {
                event.preventDefault();
                if ($("#KSFormEngineRoom").valid()) {
                    //ajaxSubmit(this, function (data) {
                    //    alert(data);
                    //    $(':input:visible', '#KSFormEngineRoom').val('');
                    //    LoadHosts();
                    //}, "/API/CIAPI/");
                    if (!CheckName("#EngineRoom_cChr_DeviceName", "机房保障")) return false;
                    AddToTable(this);
                }
                return false;
            });

            //数据库页面提交
            $('#KSFormDataBase').bind('submit', function () {
                event.preventDefault();
                if ($("#KSFormDataBase").valid()) {
                    //ajaxSubmit(this, function (data) {
                    //    alert(data);
                    //    $(':input:visible', '#KSFormDataBase').val('');
                    //    LoadHosts();
                    //}, "/API/CIAPI/");
                    if (!CheckName("#DataBase_cChr_DeviceName", "数据库")) return false;
                    AddToTable(this);
                }
                return false;
            });

            //安全设备页面提交
            $('#KSFormSafetyEquipment').bind('submit', function () {
                event.preventDefault();
                if ($("#KSFormSafetyEquipment").valid()) {
                    //ajaxSubmit(this, function (data) {
                    //    alert(data);
                    //    $(':input:visible', '#KSFormSafetyEquipment').val('');
                    //    LoadHosts();
                    //}, "/API/CIAPI/");
                    if (!CheckName("#SafetyEquipment_cChr_DeviceName", "安全设备")) return false;
                    AddToTable(this);
                }
                return false;
            });

            //其他
            $('#KSFormOther').bind('submit', function () {
                event.preventDefault();
                if ($("#KSFormOther").valid()) {
                    //ajaxSubmit(this, function (data) {
                    //    alert(data);
                    //    $(':input:visible', '#KSFormOther').val('');
                    //    LoadHosts();
                    //}, "/API/CIAPI/");
                    if (!CheckName("#Other_cChr_DeviceName", "其他")) return false;
                    AddToTable(this);
                }
                return false;
            });

            $("#gridTable1").jqGrid({
            @*url: '/API'+'@Url.Action("GetRule", "InspectionRuleAPI")',
            datatype: 'json',*@
                url: '',
                datatype: 'local',
                rowNum: 500,
                //rownumbers: true,
                colNames: ['RequestID', '名称', 'cChr_Type', '类型', '位置', 'cChr_RelatedTicketID', 'IP', 'cChr_Hostname', '指标', 'cChr_IndicatorIDs', 'Order', '', 'cChr_Jifang', 'cChr_louceng', 'cChr_jigui', 'cChr_Description'],
                colModel: [
                    { index: "1", name: "RequestID", key: true, sorttype: "text", hidden: true},
                    { index: "536870914", name: "cChr_DeviceName", sorttype: "text"},
                    { index: "536870913", name: "cChr_Type", sorttype: "text", hidden: true },
                    { index: "536870915", name: "cChr_Classification", sorttype: "text", width: 90 },
                    { index: "536870916", name: "cChr_Location", sorttype: "text", hidden: true },
                    { index: "536870917", name: "cChr_RelatedTicketID", sorttype: "text", hidden: true },
                    { index: "536870918", name: "cChr_IP", sorttype: "text", hidden: true },
                    { index: "536870919", name: "cChr_Hostname", sorttype: "text", hidden: true },
                    { index: "536870926", name: "cChr_Indicators", sorttype: "text", width: 200 },
                    { index: "536870928", name: "cChr_IndicatorIDs", sorttype: "text", hidden: true },
                    { index: "536870929", name: "cChr_OrderID", sorttype: "text", hidden: true },
                    { index: "Operation", name: "Operation", formatter: CIOperation, width: 100 },
                    { index: "536870930", name: "cChr_Jifang", sorttype: "text", hidden: true },
                    { index: "536870931", name: "cChr_louceng", sorttype: "text", hidden: true },
                    { index: "536870932", name: "cChr_jigui", sorttype: "text", hidden: true },
                    { index: "536870934", name: "cChr_Description", sorttype: "text", hidden: true },
                ],
                //rowNum: 5,
                //width: 700,
                //rowList: [10, 20, 30],
                pager: '#psortrows',
                //viewrecords: true,
                sortorder: "desc",
                //caption: "Sortable Rows Example",
                viewrecords: true,
                jsonReader: {
                    repeatitems: false,
                    id: "Object"
                },
                mtype: "GET",
                autowidth: true,
                sortname: 'cChr_OrderID',
                sortorder: 'asc',
                postData: {
                    cChr_RelatedTicketID: '@ViewBag.TicketID',
                }, //发送数据
                prmNames: {
                    id: 'Type'
                },
                scroll: true,
                scrollOffset: 0,
                height: "325",
                width: "950",
                viewrecords: true,
                gridview: true,

                onSelectRow: function () {
                },
                ondblClickRow: function () {
                },
                gridComplete: function () {
                },
                loadComplete: function () {
                },
                beforeSelectRow: function (rowid, e) {
                    //cChr_Classification: "服务器"
                    //cChr_DeviceName: "12412424"
                    //var rowData = $("#gridTable1").jqGrid('getRowData', rowid);
                    //var rowName = rowData.cChr_DeviceName;
                    //var rowType = rowData.cChr_Classification
                    //alert("名称:"+rowName+"  "+"类型:" + rowType);
                }
            });

            jQuery("#gridTable1").jqGrid('navGrid', '#psortrows', { edit: false, add: false, del: false });
            jQuery("#gridTable1").jqGrid('sortableRows');
            LoadHosts();
            //$(".custom-combobox").children().last().hide();

            $("#DialogRD").dialog({
                autoOpen: false,
                height: 400,
                width: 680,
                title: "添加指标",
                //modal:true,
                open: function (event, ui) {
                },
                close: function () {
                    //resourceDescriptionModel.Items([new Server("Virtual", null, null)]);
                }
            });

        });

        function LoadHosts() {
            var data = {};
            data["cChr_RelatedTicketID"] = '@ViewBag.TicketID';
            jQuery("#gridTable1").jqGrid("setGridParam", {
                url: "/API/CIAPI/GetObject", //设置表格的url
                datatype: "json", //设置数据类型
                postData: { strJson: data }
            }).trigger("reloadGrid");
            //CheckRule();
        }

        function CIOperation(cellvalue, options, rowObject) {
            var returnStr = '<input type="button" title="修改" class="BtnOpenRule Modify"  onClick="ModifyClick(\'' + rowObject.cChr_Classification + '\',\'' + options.rowId + '\')" value =""></input>&nbsp;&nbsp;&nbsp;&nbsp;'
            returnStr = returnStr + '<input type="button" title="删除" class="BtnOpenRule Del"  onClick="DeleteClick(\'' + options.rowId + '\',\'' + rowObject.cChr_DeviceName + '\')" value =""></input>'
            return '<center>' + returnStr + '</center>';
        };

        function ModifyClick(str1, str2) {
            $("#aux-foreground").showLoading();
            var cChr_IndicatorIDs = jQuery('#gridTable1').getRowData(str2).cChr_IndicatorIDs == " " ? "" : jQuery('#gridTable1').getRowData(str2).cChr_IndicatorIDs;
            $("#DialogRD").load("../InspectionRule/Create?TicketID=" + '@ViewBag.TicketID' + "&Name=" + cChr_IndicatorIDs + "&Type=" + str1 + "&RowId=" + str2 + "&Permission=" + $("#cChr_Office").val(), function () {
                $("#DialogRD").dialog("open");
                dialogRDInit = true;
                $("#aux-foreground").hideLoading();
            });
        }

        //Table删除按钮事件
        function DeleteClick(str, str1) {
            @*if (str.indexOf("row") >= 0) {
            var data = {};
                data['cChr_ObjectID'] = str1;
                data['cChr_TicketID'] = '@ViewBag.TicketID';
            data['cChr_MarkAsDelete'] = "Yes";
                $.ajax("/API/SMGXJPlanTicketRuleRelatedAPI?id=" + str1, {
                data: JSON.stringify(data),
                type: "PUT", contentType: "application/json",
                success: function (data) {
                }
            });
        }*@
            $("#gridTable1").jqGrid('delRowData', str);

        }

        //Rule页面关闭的回调函数
        function DialogRDClose(data,dataid, RowId) {
            $("#DialogRD").dialog("close");
            jQuery("#gridTable1").setCell(RowId, 'cChr_Indicators', data);
            jQuery("#gridTable1").setCell(RowId, 'cChr_IndicatorIDs', dataid);
            //LoadHosts();
        }

        //添加CI到表里去的通用型方法
        function AddToTable(frm) {
            var dataRow = getFormJson(frm);
            GridrowID = jQuery('#gridTable1').jqGrid('getGridParam', 'records') + 1;
            var selectedId = $("#gridTable").jqGrid("getGridParam", "selrow");
            if (selectedId) {
                $("#gridTable1").jqGrid("addRowData", "row" + GridrowID, dataRow, "after", selectedId);
            } else {
                $("#gridTable1").jqGrid("addRowData", "row" + GridrowID, dataRow, "last");
            }
            $(':input:visible', '.KSFormLittle').val('');
        }

        //检查多余的指标关联项
@*        function CheckRule() {
            $.ajax("/API/SMGXJPlanTicketRuleRelatedAPI?TicketID=" + '@ViewBag.TicketID', {
                type: "Get", contentType: "application/json",
                success: function (data) {
                }
            });
        }*@

    </script>
}